package com.itheimajdbc;
import org.junit.Test;
import javax.annotation.processing.SupportedAnnotationTypes;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
//JDBC API 详解：Statement
public class jdbcdemo_Statement {

   //执行DML语句
   @Test
    public void testDML() throws Exception{
       //注册驱动
       Class.forName("com.mysql.cj.jdbc.Driver");
       //2.获取连接：(如果是本地的mysql并且端口号默认的3306可以简化书写)
       String url = "jdbc:mysql://localhost:3306/mysql";
       String username = "root";
       String password = "123456";
       Connection conn = DriverManager.getConnection(url,username,password);
       //3.定义sql
       String sql = "update demo set money = 300 where id = 1";
       //4.获取执行sql的对象Statement
       Statement stmt = conn.createStatement();
       //5.执行sql
       int count = stmt.executeUpdate(sql);//执行受影响的行数
       //6.处理结果
       System.out.println(count);

       //7.释放资源

       stmt.close();
       conn.close();
   }
}